import {
  exportUrl,
  getLineCodeList,
  getProdOrderStatusList,
  getProdOrderTypeList,
  getPrepositionTypeList,
  getBackflushTypeList,
  getSimulatedTypeList
} from "@/api/print/mesProdOrder"
import app from "@/main"
import store from '@/store'
// 列表头按钮配置
export const operateList = [
  // {
  //   name: "导出",
  //   type: "primary",
  //   icon: "el-icon-download",
  //   handleName: "export", //点击时返回的标识
  //   url: exportUrl,
  //   //auth: "auth:operlog:export", //权限字段
  // },
  {
    name: $i18n.t("mesProdOrderMaterial.printText"),
    type: "primary",
    icon: "el-icon-printer",
    handleName: "print", //点击时返回的标识
    disabled: (data) => {
      // let orderStatus = data[0]?.orderStatus ?? "";
      // return data.length != 1 || orderStatus >= 2;
      return data.length != 1
    }
  }
]
// 行末按钮配置
export const rowConfig = [
  {
    name: $i18n.t("common.view"),
    type: "primary",
    class: "row-btn-primary",
    handleName: "show" //点击时返回的标识
  }
]
// 搜索条件配置
export const searchConfig = {
  inline: true,
  formDesc: {
    orderCode: {
      type: "input",
      label: $i18n.t("mesProdOrderMaterial.orderCode")
    },
    prodCode: {
      type: "input",
      label: $i18n.t("mesProdOrderMaterial.prodCode")
    },
    prodOrderType: {
      label: $i18n.t("mesProdOrderMaterial.prodOrderType"),
      type: "select",
      prop: {
        value: "value",
        text: "description"
      },
      options: async (data) => {
        const list = await getProdOrderTypeList()
        return list.data.result
      }
    },
    planBeginDate: {
      type: "daterange",
      label: $i18n.t("mesProdOrderMaterial.planBeginDate"),
      attrs: {
        valueFormat: "yyyy-MM-dd",
        searchArrKey: ["planBeginDateMin", "planBeginDateMax"]
      }
    },
    lineCode: {
      label: $i18n.t("common.line"),
      type: "select",
      prop: {
        value: "modelingCode",
        text: "modelingName"
      },
      options: async (data) => {
        const params = {
          modelingCode: store.getters.factoryCode,
          level: 5
        }
        const list = await getLineCodeList(params)
        return list.data.result
      }
    },
    orderStatus: {
      label: $i18n.t("mesProdOrderMaterial.orderStatus"),
      type: "select",

      prop: {
        value: "value",
        text: "description"
      },
      options: async (data) => {
        const list = await getProdOrderStatusList()
        return list.data.result
      }
    }
  }
}
// 新增/删除表单配置
export const formDescDialog = {
  span: 24,
  disabled: true,
  isShowSubmitBtn: false,
  labelPosition: "top",
  formDesc: {
    orderCode: {
      type: "input",
      label: $i18n.t("mesProdOrderMaterial.orderCode"),
      layout: 8,
      // disabled: (d) => !!d.id,
      disabled: (data) => {
        return !!data.codeStrategy || !!data.id
      }
      // required: true,
    },
    planCode: {
      type: "select",
      label: $i18n.t("mesProdOrderMaterial.planCode"),
      layout: 8,
      required: true
    },

    prodCode: {
      type: "input",
      label: $i18n.t("mesProdOrderMaterial.prodCode"),
      layout: 8,
      required: true
    },

    prodName: {
      type: "input",
      label: $i18n.t("mesProdOrderMaterial.prodName"),
      layout: 8,
      required: false,
      disabled: true
    },
    seriesCode: {
      type: "input",
      label: $i18n.t("mesProdOrderMaterial.seriesCode"),
      layout: 8,
      required: true,
      disabled: true
    },

    seriesName: {
      type: "input",
      label: $i18n.t("mesProdOrderMaterial.seriesName"),
      layout: 8,
      disabled: true
    },
    measureUnits: {
      type: "input",
      label: $i18n.t("mesProdOrderMaterial.measureUnit"),
      layout: 8,
      disabled: true
    },
    measureUnitsCode: {
      type: "input",
      label: $i18n.t("mesProdOrderMaterial.measureUnitCode"),
      layout: 8,
      disabled: true
    },
    bomVersionNumber: {
      type: "input",
      label: $i18n.t("mesProdOrderMaterial.bomVersionNumber"),
      layout: 8,
      required: false
    },
    simulatedType: {
      type: "select",
      label: $i18n.t("mesProdOrderMaterial.simulatedType"),
      layout: 8,
      required: true,
      prop: {
        value: "value",
        text: "description"
      },
      options: async (data) => {
        const list = await getSimulatedTypeList()
        return list.data.result
      }
    },
    prodOrderType: {
      type: "select",
      label: $i18n.t("mesProdOrderMaterial.prodOrderType"),
      layout: 8,
      required: true,
      prop: {
        value: "value",
        text: "description"
      },
      options: async (data) => {
        const list = await getProdOrderTypeList()
        return list.data.result
      }
    },
    // priority: {
    //   type: 'number',
    //   label: '工单优先级',
    //   layout: 8,
    //   required: true,
    //   min: 1,
    // },
    deliveryDate: {
      type: "date",
      label: $i18n.t("mesProdOrderMaterial.deliveryDate"),
      layout: 8,
      required: false,
      attrs: {
        valueFormat: "yyyy-MM-dd"
      }
    },
    slackTime: {
      type: "number",
      label: $i18n.t("mesProdOrderMaterial.slackTime"),
      layout: 8,
      required: false
    },
    quantity: {
      type: "number",
      label: $i18n.t("mesProdOrderMaterial.quantity"),
      layout: 8,
      required: true
    },

    planBeginDate: {
      type: "date",
      label: $i18n.t("mesProdOrderMaterial.planBeginDate"),
      layout: 8,
      required: true,
      attrs: {
        valueFormat: "yyyy-MM-dd"
      }
    },
    planEndDate: {
      type: "date",
      label: $i18n.t("mesProdOrderMaterial.planEndDate"),
      layout: 8,
      required: true,
      attrs: {
        valueFormat: "yyyy-MM-dd"
      }
    },
    // advanceCode: {
    //   type: "input",
    //   label: "提前定单号",
    //   layout: 8,
    //   required: false,
    // },
    backflushType: {
      type: "select",
      label: $i18n.t("mesProdOrderMaterial.backFlushType"),
      layout: 8,
      required: true,
      prop: {
        value: "value",
        text: "description"
      },
      options: async (data) => {
        const list = await getBackflushTypeList()
        return list.data.result
      }
    },

    prepositionCode: {
      type: "input",
      label: $i18n.t("mesProdOrderMaterial.prepositionCode"),
      layout: 8
      // required: true,
    },
    prepositionType: {
      type: "select",
      label: $i18n.t("mesProdOrderMaterial.prepositionType"),
      layout: 8,
      // required: true,
      prop: {
        value: "value",
        text: "description"
      },
      options: async (data) => {
        const list = await getPrepositionTypeList()
        return list.data.result
      }
    },
    remark: {
      type: "input",
      label: $i18n.t("common.remark"),
      layout: 24,
      required: false
    }
  }
}
